/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.kj.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.alibaba.fastjson.JSONValidator;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.kj.entity.KjActivityPhase;
import com.jeesite.modules.kj.service.KjActivityPhaseService;

/**
 * kj_activity_phaseController
 * @author hzy
 * @version 2021-07-22
 */
@Controller
@RequestMapping(value = "${adminPath}/kj/kjActivityPhase")
public class KjActivityPhaseController extends BaseController {

	@Autowired
	private KjActivityPhaseService kjActivityPhaseService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public KjActivityPhase get(String id, boolean isNewRecord) {
		return kjActivityPhaseService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("kj:kjActivityPhase:view")
	@RequestMapping(value = {"list", ""})
	public String list(KjActivityPhase kjActivityPhase, Model model) {
		model.addAttribute("kjActivityPhase", kjActivityPhase);
		return "modules/kj/kjActivityPhaseList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("kj:kjActivityPhase:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<KjActivityPhase> listData(KjActivityPhase kjActivityPhase, HttpServletRequest request, HttpServletResponse response) {
		kjActivityPhase.setPage(new Page<>(request, response));
		Page<KjActivityPhase> page = kjActivityPhaseService.findPage(kjActivityPhase);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("kj:kjActivityPhase:view")
	@RequestMapping(value = "form")
	public String form(KjActivityPhase kjActivityPhase, Model model) {
		model.addAttribute("kjActivityPhase", kjActivityPhase);
		return "modules/kj/kjActivityPhaseForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("kj:kjActivityPhase:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated KjActivityPhase kjActivityPhase) {
		kjActivityPhaseService.save(kjActivityPhase);
		return renderResult(Global.TRUE, text("保存活动阶段成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("kj:kjActivityPhase:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(KjActivityPhase kjActivityPhase) {
		kjActivityPhaseService.delete(kjActivityPhase);
		return renderResult(Global.TRUE, text("删除活动阶段成功！"));
	}
	
	/**
	 * 列表选择对话框
	 */
	@RequiresPermissions("kj:kjActivityPhase:view")
	@RequestMapping(value = "kjActivityPhaseSelect")
	public String empUserSelect(KjActivityPhase kjActivityPhase, String selectData, Model model) {
		String selectDataJson = EncodeUtils.decodeUrl(selectData);
		if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
			model.addAttribute("selectData", selectDataJson);
		}
		model.addAttribute("KjActivityPhase", kjActivityPhase);
		return "modules/kj/kjActivityPhaseSelect";
	}
	
}